package com.ling.pl.security.view.position;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;
import com.ling.core.common.utils.D7PageUtils;
import com.ling.pl.security.feign.DefaultPositionService;
import com.ling.pl.security.model.DefaultPositionVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

@Component("ling2.positionMaintain")
public class PositionMaintain {
    @Resource
    private DefaultPositionService positionService;

    @DataProvider
    public void loadPostions(Page<DefaultPositionVO> page, Criteria criteria)
            throws Exception {
        D7PageUtils.daoPageToPage(positionService.findDefaultPositionByPage(D7PageUtils.buildQueryParams(criteria, page)), page);
    }

    @DataProvider
    public Collection<DefaultPositionVO> loadPositionByUsername(String username) {
        return positionService.loadPositionByUsername(username);
    }

    @DataResolver
    public void savePostions(List<DefaultPositionVO> positions) {
        positionService.saveAll(positions);
    }

    @Expose
    public String uniqueCheck(String id) {
        return positionService.uniqueCheck(id);
    }
}
